﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.IO;
using SES.CMS.DO;
using SES.CMS.BL;

namespace SES.CMS
{
	public partial class Content : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
            if (Request.QueryString["ID"] != null)
            {
                int id = int.Parse(Request.QueryString["ID"].ToString());
                cmsCategoryDO objCat = new cmsCategoryDO();
                objCat.CategoryID = id;
                objCat = new cmsCategoryBL().Select(objCat);
                Page.Title = objCat.Title + " - Văn Phòng Phẩm Mỹ Đình";
                lblInfo.Text = objCat.DetailContent;
                //if ((objCat.ImageURL != null)&&(!File.Exists("/Media/" + objCat.ImageURL)))
                //    imgContent.ImageUrl = "/Media/" + objCat.ImageURL;
                //else
                //{
                //    imgContent.Visible = false;
                //    hplImg.Visible = false;
                //}
                //hplImg.NavigateUrl = "/Media/" + objCat.ImageURL;
                //
                if (id > 7)
                    id = objCat.ParentID;
                {
                    DataTable dt = new cmsCategoryBL().SelectByParent(id);
                    if (dt.Rows.Count > 0)
                    {
                        if (objCat.CategoryID > 7)
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                if (dr.ItemArray[0].ToString() == objCat.CategoryID.ToString())
                                {
                                    dt.Rows.Remove(dr);
                                    break;
                                }
                            }
                        }
                        lbl.Visible = true;
                        rptOther.Visible = true;
                        lbl.Text = "<span style=\"font-weight: bold; color:#CC0D01\">CÁC BÀI VIẾT LIÊN QUAN</span>";
                        rptOther.DataSource = dt;
                        rptOther.DataBind();
                    }
                    else
                    {
                        lbl.Visible = false;
                        rptOther.Visible = false;
                    }
                }
            }
		}
        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
        public string CheckDate(string sDate)
        {
            if (sDate != null)
            {
                //kiem tra ngay thang neu nho hon ngay hien tai (chu y parse sang datetime) 
                DateTime startDate = Convert.ToDateTime(sDate);
                DateTime now = DateTime.Now;
                TimeSpan elapsed = now.Subtract(startDate);
                double daysAgo = elapsed.TotalDays;
                if (daysAgo < 30)
                {
                    //return "<span class=\"red\">" + sDate; 
                    //return "<asp:Image ID=\"imgNew\" ImageUrl=\"~/images/New_icons_07.gif\" runat=\"server\" AlternateText=\"New\" />";
                    return "<img src=\"/images/New_icons_07.gif\" AlternateText=\"New\" />";
                }
                else
                {
                    return " ";
                }
            }
            else
            {
                return "";
            }
        }
	}
}
